<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Python笔记集 | MrLee の Blog</title><meta name="keywords" content="Python随笔"><meta name="author" content="MrLee"><meta name="copyright" content="MrLee"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="PYTHON1.Python中，使用 列表生成式 找出两个列表中不同的元素：12345678a &#x3D; [1, 3, 4, 5, 8]  b &#x3D; [5, 7, 2, 3, 5]  print([i for i in a if i not in b] + [i for i in b if i not in a])  [1, 4, 8, 7, 2]  变量倒序：  print(a[::-1])">
<meta property="og:type" content="article">
<meta property="og:title" content="Python笔记集">
<meta property="og:url" content="https://amasmrlee.gitee.io/2021/04/16/Python%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="MrLee の Blog">
<meta property="og:description" content="PYTHON1.Python中，使用 列表生成式 找出两个列表中不同的元素：12345678a &#x3D; [1, 3, 4, 5, 8]  b &#x3D; [5, 7, 2, 3, 5]  print([i for i in a if i not in b] + [i for i in b if i not in a])  [1, 4, 8, 7, 2]  变量倒序：  print(a[::-1])">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg">
<meta property="article:published_time" content="2021-04-16T01:00:00.000Z">
<meta property="article:modified_time" content="2021-04-19T03:50:28.563Z">
<meta property="article:author" content="MrLee">
<meta property="article:tag" content="Python随笔">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://amasmrlee.gitee.io/2021/04/16/Python%E7%AC%94%E8%AE%B0/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-04-19 11:50:28'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
          const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
          const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
          const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

          if (t === undefined) {
            if (isLightMode) activateLightMode()
            else if (isDarkMode) activateDarkMode()
            else if (isNotSpecified || hasNoSupport) {
              const now = new Date()
              const hour = now.getHours()
              const isNight = hour <= 6 || hour >= 18
              isNight ? activateDarkMode() : activateLightMode()
            }
            window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
              if (saveToLocal.get('theme') === undefined) {
                e.matches ? activateDarkMode() : activateLightMode()
              }
            })
          } else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="/img/avatar/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">MrLee の Blog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Python笔记集</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="fa-fw post-meta-icon far fa-calendar-alt"></i><span class="post-meta-label">发表于</span><time datetime="2021-04-16T01:00:00.000Z" title="undefined 2021-04-16 09:00:00">2021-04-16</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Python/">Python</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Python笔记集"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="PYTHON"><a href="#PYTHON" class="headerlink" title="PYTHON"></a>PYTHON</h2><h3 id="1-Python中，使用-列表生成式-找出两个列表中不同的元素："><a href="#1-Python中，使用-列表生成式-找出两个列表中不同的元素：" class="headerlink" title="1.Python中，使用 列表生成式 找出两个列表中不同的元素："></a>1.Python中，使用 <strong>列表生成式</strong> 找出两个列表中不同的元素：</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">a = [<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">8</span>]  </span><br><span class="line">b = [<span class="number">5</span>, <span class="number">7</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>]  </span><br><span class="line"><span class="built_in">print</span>([i <span class="keyword">for</span> i <span class="keyword">in</span> a <span class="keyword">if</span> i <span class="keyword">not</span> <span class="keyword">in</span> b] + [i <span class="keyword">for</span> i <span class="keyword">in</span> b <span class="keyword">if</span> i <span class="keyword">not</span> <span class="keyword">in</span> a])  </span><br><span class="line">[<span class="number">1</span>, <span class="number">4</span>, <span class="number">8</span>, <span class="number">7</span>, <span class="number">2</span>]  </span><br><span class="line"></span><br><span class="line">变量倒序：  </span><br><span class="line"><span class="built_in">print</span>(a[::-<span class="number">1</span>])        <span class="comment"># 输出：[8, 5, 4, 3, 1]  此法不会改变变量本身（a还是之前的a）</span></span><br><span class="line"><span class="built_in">print</span>(a.reverse())    <span class="comment"># 输出：[8, 5, 4, 3, 1]  此法改变了变量本身（a已不再是之前的a）</span></span><br></pre></td></tr></table></figure>
<h3 id="2-用Python搭建一个临时的HTTP站点-可通过该站点共享目录文件等等"><a href="#2-用Python搭建一个临时的HTTP站点-可通过该站点共享目录文件等等" class="headerlink" title="2.用Python搭建一个临时的HTTP站点(可通过该站点共享目录文件等等)"></a>2.用Python搭建一个临时的HTTP站点(可通过该站点<strong>共享目录文件</strong>等等)</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">1）进入待分享的目录 </span><br><span class="line">2）执行命令python -m SimpleHTTPServer 端口号 </span><br><span class="line">　 注意：不填端口号则默认使用8000端口。 </span><br><span class="line">3）浏览器访问该主机的地址：http:&#x2F;&#x2F;IP:端口号&#x2F;</span><br><span class="line">python 2版本  </span><br><span class="line">python -m SimpleHTTPServer 8080  </span><br><span class="line">python 3版本  </span><br><span class="line">python -m http.server 8080</span><br></pre></td></tr></table></figure>
<h3 id="3-virtualenv：创建python虚拟环境时，用”virtualenv-–no-site-packages-venv”命令，提示：virtualenv-error-unrecognized-arguments-–no-site-packages！！！（python3-8-1-64-bit、virtualenv20-0-4）"><a href="#3-virtualenv：创建python虚拟环境时，用”virtualenv-–no-site-packages-venv”命令，提示：virtualenv-error-unrecognized-arguments-–no-site-packages！！！（python3-8-1-64-bit、virtualenv20-0-4）" class="headerlink" title="3.virtualenv：创建python虚拟环境时，用”virtualenv –no-site-packages venv”命令，提示：virtualenv: error: unrecognized arguments: –no-site-packages！！！（python3.8.1 64-bit、virtualenv20.0.4）"></a>3.virtualenv：创建python虚拟环境时，用”virtualenv –no-site-packages venv”命令，提示：virtualenv: error: unrecognized arguments: –no-site-packages！！！（python3.8.1 64-bit、virtualenv20.0.4）</h3><p><strong>解决办法</strong>：降低 virtualenv 版本（我降到了16.7.7）<br>报错截图：<br><img src= "/img/loading.gif" data-lazy-src="/img/article_img/20200221102823194_1685.png" alt="错误截图">  </p>
<h3 id="4-VS-Code安装完成后，打开出现黑屏，或者运行python文件时出现不能运行，亦或者vscode用不了cmd（总是运行超时）"><a href="#4-VS-Code安装完成后，打开出现黑屏，或者运行python文件时出现不能运行，亦或者vscode用不了cmd（总是运行超时）" class="headerlink" title="4.VS Code安装完成后，打开出现黑屏，或者运行python文件时出现不能运行，亦或者vscode用不了cmd（总是运行超时）"></a>4.VS Code安装完成后，打开出现黑屏，或者运行python文件时出现不能运行，亦或者vscode用不了cmd（总是运行超时）</h3><p><strong>解决办法</strong>：修改软件兼容性并改为以管理员身份运行，如下：<br><img src= "/img/loading.gif" data-lazy-src="/img/article_img/20200221103956354_16976.png">  </p>
<h3 id="5-运行ipython出现以下问题（ipython-7-13-0，prompt-toolkit-3-0-3）："><a href="#5-运行ipython出现以下问题（ipython-7-13-0，prompt-toolkit-3-0-3）：" class="headerlink" title="5.运行ipython出现以下问题（ipython 7.13.0，prompt-toolkit 3.0.3）："></a>5.运行ipython出现以下问题（ipython 7.13.0，prompt-toolkit 3.0.3）：</h3><p>  <img src= "/img/loading.gif" data-lazy-src="/img/article_img/20200229101501663_15501.png"><br>  <strong>原因及解决办法</strong>：ipython 7 . 10 . 2（或ipython 7.13.0）和prompt toolkit v3.x之间存在一些不兼容之处。但是，当降级到prompt toolkit v2.x时，一切正常。github的ipython员工建议我这样做(这是他们的功劳)。  </p>
<h3 id="6-批量安装Python的第三方库："><a href="#6-批量安装Python的第三方库：" class="headerlink" title="6.批量安装Python的第三方库："></a>6.批量安装Python的第三方库：</h3><p>  <img src= "/img/loading.gif" data-lazy-src="/img/article_img/20200413141854674_2436.png">  </p>
<pre><code>1.将要安装的第三方库按照以上格式写入.txt文件中
2.命令行输入：pip install -r requirements.txt  
  
</code></pre>
<h3 id="7-使用pip-install-r-requirements-txt时有时候会提示代理问题"><a href="#7-使用pip-install-r-requirements-txt时有时候会提示代理问题" class="headerlink" title="7.使用pip install -r requirements.txt时有时候会提示代理问题"></a>7.使用<code>pip install -r requirements.txt</code>时有时候会提示代理问题</h3><p><img src= "/img/loading.gif" data-lazy-src="/img/article_img/20210415101046404_11949.png"></p>
<p>原因是升级了<code>pip</code>；当然，这是少数情况。<strong>解决办法是退回pip低版本下安装（pip==19.2.3）</strong>：  </p>
<p><img src= "/img/loading.gif" data-lazy-src="/img/article_img/20210415101147175_29259.png"></p>
<h3 id="8-使用pyinstaller打包方法"><a href="#8-使用pyinstaller打包方法" class="headerlink" title="8.使用pyinstaller打包方法"></a>8.使用pyinstaller打包方法</h3><p>第一种：把由.py文件打包而成的.exe文件及相关文件放在一个目录中。</p>
<blockquote>
<p>语法：pyinstaller 应用程序<br>eg：pyinstaller Hello.py  </p>
</blockquote>
<p>第二种：加上 -F 参数后把制作出的.exe打包成一个独立的.exe格式的可执行文件。</p>
<blockquote>
<p>语法：pyinstaller -F 应用程序<br>eg：pyinstaller -F Hello.py </p>
</blockquote>
<p>如果你的脚本文件中包含其他脚本，比如hello.py包含自定义脚本(world.py)或是系统脚本(sys.py)：则需要在打包的时候加上其他脚本的路径。<br><code>通过-p指定第三方包的路径，一条路径对应一个-p</code>  </p>
<blockquote>
<p>eg：pyinstaller -F -p C:\SystemLib\site-packages -p C:\MyLib Hello.py</p>
</blockquote>
<p>执行一次打包命令通常会生成两个目录一个附件，分别是build、dist、和xx.spec。<br>build：是编译过程中的中间产物，<br>dist：是最终可执行程序目录，<br>spec：spec文件是类似缓存，如果你第二次打包，则需要先把spec删掉，否则第二次打包会受影响。    </p>
<p><strong>pyinstaller参数介绍</strong>    </p>
<p>常用的主要是-F、-p、-i、-w这几个参数。</p>
<p>-a：不包含编码.在支持Unicode的python版本上默认包含所有的编码<br>-c：使用控制台子系统执行(默认)(只对Windows有效)<br>-d：产生debug版本的可执行文件<br>-i ：指定打包程序使用的图标（icon）文件<br>-F：打包成可执行程序<br>-h：查看帮助<br>-p：添加使用的第三方库路径<br>-v：查看 PyInstaller 版本<br>-w：取消控制台显示（默认是显示控制台的）  </p>
<p><strong>举个栗子：</strong>  </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">pyinstaller -F -p C:\SystemLib\site-packages -p C:\MyLib main.py -i C:\image\excel.ico</span><br><span class="line">解释：</span><br><span class="line">打包 main.py 脚本</span><br><span class="line">main.py包含第三方脚本，一个是系统脚本，一个是自定义脚本</span><br><span class="line">设置可执行程序的图标为excel.ico</span><br></pre></td></tr></table></figure>
<h3 id="9-django项目中出现：in-a-frame-because-it-set-‘X-Frame-Options’-to-‘deny’"><a href="#9-django项目中出现：in-a-frame-because-it-set-‘X-Frame-Options’-to-‘deny’" class="headerlink" title="9. django项目中出现：in a frame because it set ‘X-Frame-Options’ to ‘deny’."></a>9. django项目中出现：in a frame because it set ‘X-Frame-Options’ to ‘deny’.</h3><p>解决办法参考： <a target="_blank" rel="noopener" href="https://www.whbwiki.com/318.html">Django</a>  </p>
<h3 id="10-pip仓库源"><a href="#10-pip仓库源" class="headerlink" title="10. pip仓库源"></a>10. pip仓库源</h3><p>方法一（首选）：在<code>C:\Users\Administrator\pip</code>中新建文件<code>pip.ini</code>，配置以下内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[global]</span><br><span class="line">index-url &#x3D; https:&#x2F;&#x2F;pypi.tuna.tsinghua.edu.cn&#x2F;simple</span><br><span class="line">[install]</span><br><span class="line">trusted-host&#x3D;mirrors.aliyun.com</span><br></pre></td></tr></table></figure>
<p>方法二：<code>pip install pypinyin -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com</code></p>
</article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Python%E9%9A%8F%E7%AC%94/">Python随笔</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/2021/04/16/Mysql%E7%AC%94%E8%AE%B0/"><img class="prev-cover" data-lazy-src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Mysql笔记集</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="/img/avatar/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">MrLee</div><div class="author-info__description">Try harder</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/MrLeeqi/"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/MrLeeqi/" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">文章会不定期的更新！！！<br>如有疑问，请联系QQ：1012274457</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#PYTHON"><span class="toc-number">1.</span> <span class="toc-text">PYTHON</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-Python%E4%B8%AD%EF%BC%8C%E4%BD%BF%E7%94%A8-%E5%88%97%E8%A1%A8%E7%94%9F%E6%88%90%E5%BC%8F-%E6%89%BE%E5%87%BA%E4%B8%A4%E4%B8%AA%E5%88%97%E8%A1%A8%E4%B8%AD%E4%B8%8D%E5%90%8C%E7%9A%84%E5%85%83%E7%B4%A0%EF%BC%9A"><span class="toc-number">1.1.</span> <span class="toc-text">1.Python中，使用 列表生成式 找出两个列表中不同的元素：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E7%94%A8Python%E6%90%AD%E5%BB%BA%E4%B8%80%E4%B8%AA%E4%B8%B4%E6%97%B6%E7%9A%84HTTP%E7%AB%99%E7%82%B9-%E5%8F%AF%E9%80%9A%E8%BF%87%E8%AF%A5%E7%AB%99%E7%82%B9%E5%85%B1%E4%BA%AB%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E7%AD%89%E7%AD%89"><span class="toc-number">1.2.</span> <span class="toc-text">2.用Python搭建一个临时的HTTP站点(可通过该站点共享目录文件等等)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-virtualenv%EF%BC%9A%E5%88%9B%E5%BB%BApython%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83%E6%97%B6%EF%BC%8C%E7%94%A8%E2%80%9Dvirtualenv-%E2%80%93no-site-packages-venv%E2%80%9D%E5%91%BD%E4%BB%A4%EF%BC%8C%E6%8F%90%E7%A4%BA%EF%BC%9Avirtualenv-error-unrecognized-arguments-%E2%80%93no-site-packages%EF%BC%81%EF%BC%81%EF%BC%81%EF%BC%88python3-8-1-64-bit%E3%80%81virtualenv20-0-4%EF%BC%89"><span class="toc-number">1.3.</span> <span class="toc-text">3.virtualenv：创建python虚拟环境时，用”virtualenv –no-site-packages venv”命令，提示：virtualenv: error: unrecognized arguments: –no-site-packages！！！（python3.8.1 64-bit、virtualenv20.0.4）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-VS-Code%E5%AE%89%E8%A3%85%E5%AE%8C%E6%88%90%E5%90%8E%EF%BC%8C%E6%89%93%E5%BC%80%E5%87%BA%E7%8E%B0%E9%BB%91%E5%B1%8F%EF%BC%8C%E6%88%96%E8%80%85%E8%BF%90%E8%A1%8Cpython%E6%96%87%E4%BB%B6%E6%97%B6%E5%87%BA%E7%8E%B0%E4%B8%8D%E8%83%BD%E8%BF%90%E8%A1%8C%EF%BC%8C%E4%BA%A6%E6%88%96%E8%80%85vscode%E7%94%A8%E4%B8%8D%E4%BA%86cmd%EF%BC%88%E6%80%BB%E6%98%AF%E8%BF%90%E8%A1%8C%E8%B6%85%E6%97%B6%EF%BC%89"><span class="toc-number">1.4.</span> <span class="toc-text">4.VS Code安装完成后，打开出现黑屏，或者运行python文件时出现不能运行，亦或者vscode用不了cmd（总是运行超时）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E8%BF%90%E8%A1%8Cipython%E5%87%BA%E7%8E%B0%E4%BB%A5%E4%B8%8B%E9%97%AE%E9%A2%98%EF%BC%88ipython-7-13-0%EF%BC%8Cprompt-toolkit-3-0-3%EF%BC%89%EF%BC%9A"><span class="toc-number">1.5.</span> <span class="toc-text">5.运行ipython出现以下问题（ipython 7.13.0，prompt-toolkit 3.0.3）：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E6%89%B9%E9%87%8F%E5%AE%89%E8%A3%85Python%E7%9A%84%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%EF%BC%9A"><span class="toc-number">1.6.</span> <span class="toc-text">6.批量安装Python的第三方库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E4%BD%BF%E7%94%A8pip-install-r-requirements-txt%E6%97%B6%E6%9C%89%E6%97%B6%E5%80%99%E4%BC%9A%E6%8F%90%E7%A4%BA%E4%BB%A3%E7%90%86%E9%97%AE%E9%A2%98"><span class="toc-number">1.7.</span> <span class="toc-text">7.使用pip install -r requirements.txt时有时候会提示代理问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E4%BD%BF%E7%94%A8pyinstaller%E6%89%93%E5%8C%85%E6%96%B9%E6%B3%95"><span class="toc-number">1.8.</span> <span class="toc-text">8.使用pyinstaller打包方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-django%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%87%BA%E7%8E%B0%EF%BC%9Ain-a-frame-because-it-set-%E2%80%98X-Frame-Options%E2%80%99-to-%E2%80%98deny%E2%80%99"><span class="toc-number">1.9.</span> <span class="toc-text">9. django项目中出现：in a frame because it set ‘X-Frame-Options’ to ‘deny’.</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-pip%E4%BB%93%E5%BA%93%E6%BA%90"><span class="toc-number">1.10.</span> <span class="toc-text">10. pip仓库源</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2021 By MrLee</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my <a href="https://amasmrlee.gitee.io">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (true){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="true" data-click="true"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>